package com.stylefeng.guns.modular.system.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.stylefeng.guns.common.persistence.model.CpciaNews;
import com.stylefeng.guns.modular.system.processor.CpciaNewsProcessor;
import com.stylefeng.guns.modular.system.service.ICpciaNewsService;
import com.stylefeng.guns.modular.system.service.ICpciaNewsTaskService;

@Service
@Transactional
public class CpciaNewsTaskImpl implements ICpciaNewsTaskService {
	
	@Autowired
	ICpciaNewsService cpciaNewsService;
	
	//@Scheduled(cron = "0 0 */2 * * ?")
	//@Scheduled(fixedRate=1000*120)
	@Override
    public void cpciaNewsTask(){  
        System.out.println("Annotation：cpciaNewsTask begin.....");  
        CpciaNewsProcessor cpciaNewsProcessor = new CpciaNewsProcessor();
		List<CpciaNews> cpciaNewsList =  cpciaNewsProcessor.getCpciaNews();
		for (CpciaNews cpciaNews : cpciaNewsList) {
			String title = cpciaNews.getTitle();
			List<CpciaNews> cpciaNewsListTem = cpciaNewsService.selectByTitle(title);
			if (cpciaNewsListTem==null||cpciaNewsListTem.size()<1) {
				cpciaNewsService.insertCpciaNews(cpciaNews);
			}
			
		}
		System.out.println("Annotation：cpciaNewsTask end.....");  
    } 
}
